//package paper.util;
//
//import keter.dao.org.AccountDao;
//import keter.domain.Account;
//import keter.util.AccountUtil;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationListener;
//import org.springframework.context.event.ContextRefreshedEvent;
//import org.springframework.transaction.annotation.Transactional;
//
//import paper.dao.StudentDao;
//import paper.domain.User;
//
///**
// * This class programatically populates the database at application startup. You
// * may probably wish to disable it in a production environment.
// * 
// * @author Daniel
// * 
// */
//public class PaperDbInit implements ApplicationListener<ContextRefreshedEvent> {
//
//	private static final Logger logger = LoggerFactory.getLogger(PaperDbInit.class);
//	
//	@Autowired
//	private AccountDao aDao;
//	
//	@Autowired
//	private TeacherDao tDao;
//	
//	@Autowired
//	private StudentDao sDao;
//	
//	private boolean alreadyInitialized = false;
//
//	@Transactional
//	@Override
//	public void onApplicationEvent(ContextRefreshedEvent event) {
//		if (alreadyInitialized) {
//			return;
//		}
//		if (aDao.findByName("admin") != null) {
//			logger.info("系统已被初始化或用户数据已存在。");
//			return;
//		}
//		//管理员老师
//		Account adminTeacherAccount = AccountUtil.buildAdmin();		
//		Teacher adminTeacher = UserBuildUtil.buildAdminTeacher(adminTeacherAccount);
//		tDao.save(adminTeacher);
//	 
//	    //普通老师
//	    Account teacherAccount = AccountUtil.buildTeacherAccount("teacher");	    
//	    Teacher teacher  = UserBuildUtil.buildTeacher(teacherAccount);
//	    tDao.save(teacher);
//	    
//	    //学生
//		Account studentAccount = AccountUtil.buildStudentAccount("s","3");
//		User student = UserBuildUtil.buildStudent(studentAccount);
//		student.setAccount(studentAccount);  
//		//普通老师是学生的导师
//		student.setTeacher(teacher);
//		student.getAccount().getUnitList().add(UserBuildUtil.childUnit());
//		sDao.save(student);
//	 	    
//		alreadyInitialized = true;
//		logger.info("系统数据初始化完毕！");
//	}
//	
//}